package domain;

import java.util.Date;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Access(AccessType.PROPERTY)
public class Registration extends DomainEntity {
	
	// Constructors 
		public Registration(){
			super();
		}

	

		// Attributes -------------------------------------------------------------
		private Date registrationDate;
		private Assessment assessment;
		
		@NotNull
		@Past
		@Temporal(TemporalType.TIMESTAMP)
		@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
		public Date getRegistrationDate() {
			return registrationDate;
		}
		public void setRegistrationDate(Date registrationDate) {
			this.registrationDate = registrationDate;
		}
		
		@Valid
		@AttributeOverrides({
			@AttributeOverride(name="rate", 
				column=@Column(name="participantRate")),
			@AttributeOverride(name="comment", 
				column=@Column(name="participantComment"))
		})
		public Assessment getAssessment() {
			return assessment;
		}

		public void setAssessment(Assessment assessment) {
			this.assessment = assessment;
		}
				
		// Relationships ----------------------------------------------------------
		
		private Event event;
		private Participant participant;
		
		@NotNull
		@Valid
		@ManyToOne(optional = false)
		public Event getEvent() {
			return event;
		}
		public void setEvent(Event event) {
			this.event = event;
		}
		
		@NotNull
		@Valid
		@ManyToOne(optional = false)
		public Participant getParticipant() {
			return participant;
		}

		public void setParticipant(Participant participant) {
			this.participant = participant;
		}
}
